package com.caogen.cg_wl_kt.base

import android.app.Activity
import android.content.Context
import com.caogen.cg_wl_kt.model.UserBean
import com.caogen.cg_wl_kt.utils.ToastUtils
import com.caogen.cg_wl_kt.utils.YDLog
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody

/**
 * 项目名称: cg_wl_kt
 * Packages:com.caogen.cg_wl_kt.base
 * author: FSW
 * 创建日期: 2024/2/26 12:00
 * Describe:
 *
 */
open class BaseP{
    fun logi(msg: String) {
        YDLog.logi(msg)
    }
    fun logs(msg: String) {
        YDLog.logi(msg)
    }

    fun loge(msg: String) {
        YDLog.loge(msg)
    }

    fun toast(msg: String) = ToastUtils.showShortSafe(msg)

    fun toastLong(msg: String) = ToastUtils.showLongSafe(msg)

    fun ui(activity: Activity, block: () -> Unit) {
        activity.runOnUiThread {
            block()
        }
    }
//    fun context(context: Context, block: () -> Unit) {
//        context.run {
//            block()
//        }
//    }

    fun threadName(): String {
        return Thread.currentThread().name
    }
    fun toRequestBody(value: String): RequestBody {
        return RequestBody.create("text/plain".toMediaTypeOrNull(), value)
    }
    fun toMapRequestBody(params: MutableMap<String, String>): HashMap<String, RequestBody> {
        val map = HashMap<String,RequestBody>()
        params.forEach { (key, value) ->
            map[key] = toRequestBody(value)
        }
        return map;
    }
    interface OnListCallBack {
        fun <T> onSuccess(data: ArrayList<T>?)
        fun <T> onError(data: ArrayList<T>?)
    }
    interface OnBeanCallBack {
        fun <T>  onSuccess(data: T?)
        fun <T>  onError(data: T?)
    }
}